<?php 
	namespace Home\Controller;
	use Hdphp\Controller\Controller;
	use Home\Model\StuDetail;
	use Home\Model\Students;
	class XiaoshouController extends CommonController{
		public function __init(){

		}
		public function index(){
			$to=$_SESSION['userinfo']['uid'];
			$data=Db::table('students')->where('`to`',$to)->get();
			View::with('data',$data);
			View::make();
		}
		public function editStu(){
			$sid=q('get.sid');
			$data=Db::table('students s')->leftjoin('stu_detail sd','s.sid','=','sd.sid')->where('s.sid',$sid)->first();
			if(IS_POST){
				$studetail=new StuDetail;
				$stu=new Students;
				if($stu->create()){
					$stu->save();
				}
				$data=$studetail->where('sid',$sid)->find();
				if($post=$studetail->create()){
					if(isset($data)){
						$res=$studetail->where('sid',$sid)->update($post);
					}else{
						$res=$studetail->add($post);
					}
					if($res){
						View::success('完善成功',U('index'));
					}else{
						View::error('完善失败');
					}
				}
			}
			View::with('data',$data);
			View::make();
		}

		public function editStat(){
			$state=q('get.state');
			$sid=q('get.sid');
			$res=Db::table('students')->where('sid',$sid)->update(array('state'=>$state));
			if($res!==false){
				View::success('更新成功');
			}else{
				View::error('更新失败');
			}
		}
	}
?>